package be.novelfaces.showcase.webdriver.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import be.novelfaces.showcase.webdriver.util.NFBy;

public class NumpadDecimalSeparatorPage extends BasePage {
	private Select select;
	private boolean arrivedAt(String contentHeaderTitle){
    	return driver.findElement(By.id("contentHeader")).getText().contains(contentHeaderTitle);
    }
	
	public NumpadDecimalSeparatorPage(WebDriver driver) {
		super(driver);
		select = new Select(driver.findElement(NFBy.mainFormId("locale")));
		if(!arrivedAt("Component - Numpad decimal separator")) {
			throw new IllegalStateException("This is not the " + "Component - Numpad decimal separator" + " page");
		}
	}
	
	public void setValueOfLocaleSelect(String value){
		select.selectByValue(value);
		waitForAjaxToComplete();
	}
	
	public String getValueOfInput(){
		return getInputElement().getValue();
	}
	
	public void typeDecimalSeparatorInInput(){
		getInputElement().sendKeys(Keys.DECIMAL);
	}

	private WebElement getInputElement() {
		return driver.findElement(NFBy.mainFormId("input"));
	}
	
}
